//
//  YTETWalletCell.m
//  yitaicaijing
//
//  Created by DIANGHONG on 2018/9/12.
//  Copyright © 2018年 DIANGHONG. All rights reserved.
//

#import "YTETWalletCell.h"
@interface YTETWalletCell ()
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UILabel *coinLabel;
@property (weak, nonatomic) IBOutlet UIButton *deleteButton;
@property (weak, nonatomic) IBOutlet UIButton *editButton;

@end
@implementation YTETWalletCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
    [self corRadusBorderWithView:self.deleteButton];
    [self corRadusBorderWithView:self.editButton];
}

- (void)setModel:(YTWalletAddrModel *)model
{
    _model = model;
    
    self.nameLabel.text = model.name;
    self.coinLabel.text = [NSString stringWithFormat:@"兑换币种：%@",model.product_name];
}

- (void)corRadusBorderWithView:(UIView *)view
{
    view.layer.cornerRadius = 5;
    view.layer.masksToBounds = YES;
    view.layer.borderWidth = 1;
    view.layer.borderColor = [UIColor.blackColor CGColor];
}

#pragma mark: - 编辑按钮 监听
- (IBAction)editButtonClick:(UIButton *)sender
{
    NSAssert(self.editeBtnClickBlock != nil, @"editeBtnClickBlock 不能为nil");
    self.editeBtnClickBlock(self.model.ID);
}

#pragma mark: - 删除按钮 监听
- (IBAction)deleteButtonClick:(UIButton *)sender {
    
    sender.enabled = false;
    [YTNetworkManager.shareManager requestDeleteAddrWithIsWallet:YES
                                                              ID:self.model.ID
                                                      completion:^(BOOL isSucc, NSString *error)
     {
         NSAssert(self.deleteAddrBtnClickBlock != nil, @"deleteAddrBtnClickBlock 不能为nil");
         sender.enabled = YES;
         if (!isSucc) {
             self.deleteAddrBtnClickBlock(false, error);
             return ;
         }
         
         self.deleteAddrBtnClickBlock(YES, nil);
     }];
}

@end
